package org.xmdl.silk.visit;

import org.xmdl.silk.NumDouble;
import org.xmdl.silk.NumInteger;
import org.xmdl.silk.ParaGroup;
import org.xmdl.silk.interpreter.Operator;

public class ToString extends VisitorAdapter {

	StringBuffer sb = new StringBuffer();

	
	@Override
	public boolean visit(NumDouble host) {
		sb.append(host.getValue());
		return super.visit(host);
	}

	@Override
	public boolean visit(NumInteger host) {
		sb.append(host.getValue());
		return super.visit(host);
	}

	@Override
	public boolean visitEnter(ParaGroup host) {
		sb.append("(");
		return super.visitEnter(host);
	}

	@Override
	public boolean visitLeave(ParaGroup host) {
		sb.append(")");
		return super.visitLeave(host);
	}

	public void reset() {
		sb.setLength(0);
	}

	@Override
	public String toString() {
		return sb.toString();
	}

	@Override
	public boolean visitLeave(Operator op) {
		sb.append(" ").append(op.getLiteral()).append(" ");
		return super.visitLeave(op);
	}

	
}
